var protocole = "http";
//var host = "192.168.43.5"
var host = "dev.ulysseroland.fr";
//var host = "localhost"
var port = 80;
var method = "GET";
var typeData = "json";
	
var interactionWebService = {
		creerPartie : function(onResponse, onError, idScenario) {
			requete("Suivi/CreerPartie", 
					"scenario=" + idScenario, 
					onResponse, 
					onError);
		},
		listeEquipes: function(onResponse, onError, mdpPartie) {
			requete("Suivi/ListeEquipes", 
					"mdpEnquete=" + mdpPartie, 
					onResponse, 
					onError);
		},
		infoEquipe: function(onResponse, onError, idEquipe) {
			requete("Suivi/InfoEquipe", 
					"equipeId=" + idEquipe, 
					onResponse, 
					onError);
		},
		listeScenario: function(onResponse, onError) {
			requete("Suivi/ListeScenarios", 
					"", 
					onResponse, 
					onError);
		},
		demarrerPartie: function(onResponse, onError, mdpPartie) {
			requete("Suivi/DemarrerPartie", 
					"mdpEnquete=" + mdpPartie, 
					onResponse, 
					onError);
		},
		// CurrentGame MAP / RECAP
		positionEquipes: function(onResponse, onError, mdpPartie) {
			requete("Suivi/PositionEquipes", 
					"mdpEnquete=" + mdpPartie, 
					onResponse, 
					onError);
		},
		// CurrentTeam MAP / RECAP
		etapesEquipe: function(onResponse, onError, equipeId) {
			requete("Suivi/EtapesEquipe", 
					"equipeId=" + equipeId, 
					onResponse, 
					onError);
		},
		equipeEtapesDetails: function(onResponse, onError, idEquipe) {
			requete("Suivi/EquipeEtapesDetails", 
					"equipeId=" + idEquipe, 
					onResponse, 
					onError);
		},
		// CurrentGames
		currentGames: function(onResponse, onError) {
			requete("Suivi/CurrentGames",
					"", 
					onResponse, 
					onError);
		}
};

function requete(service, params, onResponse, onErreur) {
	$.ajax({
		url: protocole + "://" + host + ":" + port + "/AndroWeb/" + service + ".php",
		type: method,
        dataType: typeData,
        data: params,
        error: function (jqXHR, textStatus, errorThrown) {
            onErreur(errorThrown);
        },
        success: function (data) {
        	if (data == null || typeof(data.erreur) === 'undefined') {
        		onResponse(data);
        	} else {
        		onErreur(data.erreur);
        	}
        }
    });
}
